<?php
/**
 * 登录管理
 * User: raisound
 * Date: 2021/10/13
 */
namespace app\api\controller;
use app\BaseController;
use think\facade\Db;
class Login extends BaseController
{
    public function initialize()
    {
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: X-Token,Content-Type, Content-Length, Authorization, Accept, X-Requested-With, Current-Page');
        header('Access-Control-Allow-Methods: POST,GET,OPTIONS,DELETE,PUT');
        parent::initialize();
    }

    /**
     * 用户登录验证
     * @return \josn
     */
    public function signIn()
    {
        try{
            // 数据接收
            $user_number = input("param.number");
            $user_pass = input("param.password");
            $data = [
                'number' =>$user_number,
                'password' =>$user_pass,
            ];
            // 验证字段
            $validate = (new \app\api\validate\UserInfo())->scene('sign_in');
            if(!$validate->check($data)){
                return returnResult(config("config.code.error"),$validate->getError());
            }
            // 业务处理
            $result = \app\api\business\LoginBus::login($data);
            if($result){
                return returnResult(config("config.code.success"),config("config.describe.login_successful"),$result);
            }else{
                return returnResult(config("config.code.error"),config("config.describe.login_failed"));
            }
        }catch (\Exception $e){
            exception($e,'Login.signIn');
        }
    }
}
